#include <gr_graph_fun.h>
#include "interface.h"
#include "list_model.h"
#include "stats.h"

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
  gtk_object_set_data_full (GTK_OBJECT (component), name, \
    gtk_widget_ref (widget), (GtkDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
  gtk_object_set_data (GTK_OBJECT (component), name, widget)

static GnomeUIInfo menuFile_menu_uiinfo[] =
{
  GNOMEUIINFO_MENU_SAVE_ITEM (saveLOGML, NULL),
  GNOMEUIINFO_MENU_SAVE_AS_ITEM (saveLOGMLAs, NULL),
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_MENU_EXIT_ITEM (gtk_main_quit, NULL),
  GNOMEUIINFO_END
};

static GnomeUIInfo menuHelp_menu_uiinfo[] =
{
  GNOMEUIINFO_MENU_ABOUT_ITEM (showAbout, NULL),
  GNOMEUIINFO_END
};

static GnomeUIInfo menubarMain_uiinfo[] =
{
  GNOMEUIINFO_MENU_FILE_TREE (menuFile_menu_uiinfo),
  GNOMEUIINFO_MENU_HELP_TREE (menuHelp_menu_uiinfo),
  GNOMEUIINFO_END
};
  
static GnomeUIInfo menu1_uiinfo[] =
{
  GNOMEUIINFO_END
};

GtkWidget*
create_appW3Live (w3lclient *w3lc)
{
	GtkWidget *appW3Live;
	GdkPixbuf *appW3Live_icon_pixbuf;
	GtkWidget *bonobodock1;
	GtkWidget *notebookData;
	GtkWidget *frameActiveUsers;
	GtkWidget *vboxActiveUsers;
	GtkWidget *tableUsersRefresh;
	GtkWidget *labelRefreshRate;
	GtkWidget *buttonRefreshUsers;
	GtkWidget *imageRefresh;
	GtkObject *spinbuttonRefreshRate_adj;
	GtkWidget *spinbuttonRefreshRate;
	GtkWidget *scrolledwindowUsers;
	GtkWidget *treeviewUsers;
	GtkWidget *labelActiveUsers;
	GtkWidget *labelPageUsers;
	GtkWidget *vboxGraph;
	GtkWidget *hboxGraph;
	GtkWidget *frameGraphButtons;
	GtkWidget *vbuttonboxGraphButtons;
	GtkWidget *buttonViewWebgraph;
	GtkWidget *alignmentVWG;
	GtkWidget *hboxVWG;
	GtkWidget *imageVWGWarn;
	GtkWidget *labelViewWebGraph;
	GtkWidget *labelGraphButtons;
	GtkWidget *frameUserPaths;
	GtkWidget *vboxUserPaths;
	GtkWidget *hboxGraphDataRefresh;
	GtkWidget *buttonRefreshGraph;
	GtkWidget *optionmenuUsers;
	GtkWidget *menu1;
	GtkWidget *scrolledwindowPaths;
	GtkWidget *treeviewGraph;
	GtkWidget *labelUserPaths;
	GtkWidget *labelPageGraph;
	GtkWidget *appbarMain;

	GtkWidget *vpanedMonitor;
	GtkWidget *scrolledwindowMonitors;
	GtkWidget *treeviewMonitors;
	GtkWidget *notebookMonitorConfig;
	GtkWidget *vboxDescription;
	GtkWidget *labelDescription;
	GtkWidget *scrolledwindowDescription;
	GtkWidget *textviewMonitorDescription;
	GtkWidget *labelTabDescription;
	GtkWidget *vboxConfigure;
	GtkWidget *labelConfiguration;

	GtkWidget *labelTabConfigure;
	GtkWidget *vboxMActionSup;
	GtkWidget *labelMAction;
	GtkWidget *vboxMActionSub;
	GtkWidget *hboxMActionPopup;
	GtkWidget *radiobuttonActionPopup;
	GSList *radiobuttonActionPopup_group = NULL;
	GtkWidget *hseparatorMAction;
	GtkWidget *hboxMActionExecute;
	GtkWidget *radiobuttonActionExecute;
	GtkWidget *vboxScript;
	GtkWidget *fileentryMExeFile;
	GtkWidget *combo_entryMExeFile;
	GtkWidget *hbuttonboxScript;
	GtkWidget *buttonMButtonScripts;
	GtkWidget *alignmentMButtonScripts;
	GtkWidget *hboxButtonMButtonScripts;
	GtkWidget *imageMButtonScripts;
	GtkWidget *labelMButtonScripts;
	GtkWidget *labelTabAction;
	GtkWidget *labelTabMonitor;

	pthread_t tid;

	appW3Live = gnome_app_new ("W3ln", "w3live");
	gtk_widget_set_name (appW3Live, "appW3Live");
	gtk_window_set_position (GTK_WINDOW (appW3Live), GTK_WIN_POS_MOUSE);
	gtk_window_set_default_size (GTK_WINDOW (appW3Live), 640, 480);
	gtk_window_set_wmclass (GTK_WINDOW (appW3Live), "w3live", "");
	appW3Live_icon_pixbuf = create_pixbuf ("w3live/w3live.xpm");
	if (appW3Live_icon_pixbuf)
	 {
   	gtk_window_set_icon (GTK_WINDOW (appW3Live), appW3Live_icon_pixbuf);
   	gdk_pixbuf_unref (appW3Live_icon_pixbuf);
	 }

	bonobodock1 = GNOME_APP (appW3Live)->dock;
	gtk_widget_set_name (bonobodock1, "bonobodock1");
	gtk_widget_show (bonobodock1);

	gnome_app_create_menus (GNOME_APP (appW3Live), menubarMain_uiinfo);

	gtk_widget_set_name (menubarMain_uiinfo[0].widget,   "menuFile");
	gtk_widget_set_name (menuFile_menu_uiinfo[0].widget, "menuSave");
	gtk_widget_set_name (menuFile_menu_uiinfo[1].widget, "menuSaveAs");
	gtk_widget_set_name (menuFile_menu_uiinfo[2].widget, "separator1");
	gtk_widget_set_name (menuFile_menu_uiinfo[3].widget, "menuQuit");
	gtk_widget_set_name (menubarMain_uiinfo[1].widget,   "menuHelp");
	gtk_widget_set_name (menuHelp_menu_uiinfo[0].widget, "menuAbout");

	notebookData = gtk_notebook_new ();
	gtk_widget_set_name (notebookData, "notebookData");
	gtk_widget_show (notebookData);
	gnome_app_set_contents (GNOME_APP (appW3Live), notebookData);

	frameActiveUsers = gtk_frame_new (NULL);
	gtk_widget_set_name (frameActiveUsers, "frameActiveUsers");
	gtk_widget_show (frameActiveUsers);
	gtk_container_add (GTK_CONTAINER (notebookData), frameActiveUsers);

	vboxActiveUsers = gtk_vbox_new (FALSE, 0);
	gtk_widget_set_name (vboxActiveUsers, "vboxActiveUsers");
	gtk_widget_show (vboxActiveUsers);
	gtk_container_add (GTK_CONTAINER (frameActiveUsers), vboxActiveUsers);

	tableUsersRefresh = gtk_table_new (1, 3, FALSE);
	gtk_widget_set_name (tableUsersRefresh, "tableUsersRefresh");
	gtk_widget_show (tableUsersRefresh);
	gtk_box_pack_start (GTK_BOX (vboxActiveUsers), tableUsersRefresh, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (tableUsersRefresh), 3);
	gtk_table_set_row_spacings (GTK_TABLE (tableUsersRefresh), 5);
	gtk_table_set_col_spacings (GTK_TABLE (tableUsersRefresh), 5);

	labelRefreshRate = gtk_label_new ("Refresh Rate:");
	gtk_widget_set_name (labelRefreshRate, "labelRefreshRate");
	gtk_widget_show (labelRefreshRate);
	gtk_table_attach (GTK_TABLE (tableUsersRefresh), labelRefreshRate, 1, 2, 0, 1,
               	  (GtkAttachOptions) (GTK_FILL),
               	  (GtkAttachOptions) (0), 0, 0);
	gtk_label_set_justify (GTK_LABEL (labelRefreshRate), GTK_JUSTIFY_LEFT);
	gtk_misc_set_alignment (GTK_MISC (labelRefreshRate), 0, 0.5);

	buttonRefreshUsers = gtk_button_new ();
	gtk_widget_set_name (buttonRefreshUsers, "buttonRefreshUsers");
	gtk_widget_show (buttonRefreshUsers);
	gtk_table_attach (GTK_TABLE (tableUsersRefresh), buttonRefreshUsers, 0, 1, 0, 1,
               	  (GtkAttachOptions) (0),
               	  (GtkAttachOptions) (0), 0, 0);

	imageRefresh = gtk_image_new_from_stock ("gtk-refresh", GTK_ICON_SIZE_BUTTON);
	gtk_widget_set_name (imageRefresh, "imageRefresh");
	gtk_widget_show (imageRefresh);
	gtk_container_add (GTK_CONTAINER (buttonRefreshUsers), imageRefresh);

	spinbuttonRefreshRate_adj = gtk_adjustment_new (30, 5, 3600, 1, 60, 60);
	spinbuttonRefreshRate = gtk_spin_button_new (GTK_ADJUSTMENT (spinbuttonRefreshRate_adj), 1, 0);
	gtk_widget_set_name (spinbuttonRefreshRate, "spinbuttonRefreshRate");
	gtk_widget_show (spinbuttonRefreshRate);
	gtk_table_attach (GTK_TABLE (tableUsersRefresh), spinbuttonRefreshRate, 2, 3, 0, 1,
               	  (GtkAttachOptions) (0),
               	  (GtkAttachOptions) (0), 0, 0);
	gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbuttonRefreshRate), TRUE);

	scrolledwindowUsers = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_set_name (scrolledwindowUsers, "scrolledwindowUsers");
	gtk_widget_show (scrolledwindowUsers);
	gtk_box_pack_start (GTK_BOX (vboxActiveUsers), scrolledwindowUsers, TRUE, TRUE, 0);

	treeviewUsers = create_view_and_model_Users();
	gtk_widget_set_name (treeviewUsers, "treeviewUsers");
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeviewUsers), TRUE);
	gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeviewUsers), TRUE);
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(treeviewUsers), TRUE);
	//gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW(treeviewUsers), TRUE);
	gtk_tree_view_set_reorderable (GTK_TREE_VIEW(treeviewUsers), TRUE);
	//gtk_tree_view_set_enable_search (GTK_TREE_VIEW(treeviewUsers), TRUE);
	//gtk_tree_view_set_search_column (GTK_TREE_VIEW(treeviewUsers), COL_SITE);

	gtk_widget_show (treeviewUsers);
	gtk_container_add (GTK_CONTAINER (scrolledwindowUsers), treeviewUsers);

	labelActiveUsers = gtk_label_new ("Active Users");
	gtk_widget_set_name (labelActiveUsers, "labelActiveUsers");
	gtk_widget_show (labelActiveUsers);
	gtk_frame_set_label_widget (GTK_FRAME (frameActiveUsers), labelActiveUsers);
	gtk_label_set_justify (GTK_LABEL (labelActiveUsers), GTK_JUSTIFY_LEFT);

	labelPageUsers = gtk_label_new ("Users");
	gtk_widget_set_name (labelPageUsers, "labelPageUsers");
	gtk_widget_show (labelPageUsers);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebookData), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebookData), 0), labelPageUsers);
	gtk_label_set_justify (GTK_LABEL (labelPageUsers), GTK_JUSTIFY_LEFT);

	vboxGraph = gtk_vbox_new (FALSE, 0);
	gtk_widget_set_name (vboxGraph, "vboxGraph");
	gtk_widget_show (vboxGraph);
	gtk_container_add (GTK_CONTAINER (notebookData), vboxGraph);

	hboxGraph = gtk_hbox_new (FALSE, 0);
	gtk_widget_set_name (hboxGraph, "hboxGraph");
	gtk_widget_show (hboxGraph);
	gtk_box_pack_start (GTK_BOX (vboxGraph), hboxGraph, TRUE, TRUE, 0);

	frameGraphButtons = gtk_frame_new (NULL);
	gtk_widget_set_name (frameGraphButtons, "frameGraphButtons");
	gtk_widget_show (frameGraphButtons);
	gtk_box_pack_start (GTK_BOX (hboxGraph), frameGraphButtons, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (frameGraphButtons), 3);

	vbuttonboxGraphButtons = gtk_vbutton_box_new ();
	gtk_widget_set_name (vbuttonboxGraphButtons, "vbuttonboxGraphButtons");
	gtk_widget_show (vbuttonboxGraphButtons);
	gtk_container_add (GTK_CONTAINER (frameGraphButtons), vbuttonboxGraphButtons);
	gtk_container_set_border_width (GTK_CONTAINER (vbuttonboxGraphButtons), 3);
	gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonboxGraphButtons), GTK_BUTTONBOX_START);
	gtk_button_box_set_spacing (GTK_BUTTON_BOX (vbuttonboxGraphButtons), 5);

	buttonViewWebgraph = gtk_button_new ();
	gtk_widget_set_name (buttonViewWebgraph, "buttonViewWebgraph");
	gtk_widget_show (buttonViewWebgraph);
	gtk_container_add (GTK_CONTAINER (vbuttonboxGraphButtons), buttonViewWebgraph);
	GTK_WIDGET_SET_FLAGS (buttonViewWebgraph, GTK_CAN_DEFAULT);

	alignmentVWG = gtk_alignment_new (0.5, 0.5, 0, 0);
	gtk_widget_set_name (alignmentVWG, "alignmentVWG");
	gtk_widget_show (alignmentVWG);
	gtk_container_add (GTK_CONTAINER (buttonViewWebgraph), alignmentVWG);

	hboxVWG = gtk_hbox_new (FALSE, 2);
	gtk_widget_set_name (hboxVWG, "hboxVWG");
	gtk_widget_show (hboxVWG);
	gtk_container_add (GTK_CONTAINER (alignmentVWG), hboxVWG);

	imageVWGWarn = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_BUTTON);
	gtk_widget_set_name (imageVWGWarn, "imageVWGWarn");
	gtk_widget_show (imageVWGWarn);
	gtk_box_pack_start (GTK_BOX (hboxVWG), imageVWGWarn, FALSE, FALSE, 0);

	labelViewWebGraph = gtk_label_new_with_mnemonic ("View Webgraph");
	gtk_widget_set_name (labelViewWebGraph, "labelViewWebGraph");
	gtk_widget_show (labelViewWebGraph);
	gtk_box_pack_start (GTK_BOX (hboxVWG), labelViewWebGraph, FALSE, FALSE, 0);
	gtk_label_set_justify (GTK_LABEL (labelViewWebGraph), GTK_JUSTIFY_LEFT);

	labelGraphButtons = gtk_label_new ("Graph");
	gtk_widget_set_name (labelGraphButtons, "labelGraphButtons");
	gtk_widget_show (labelGraphButtons);
	gtk_frame_set_label_widget (GTK_FRAME (frameGraphButtons), labelGraphButtons);
	gtk_label_set_justify (GTK_LABEL (labelGraphButtons), GTK_JUSTIFY_LEFT);

	frameUserPaths = gtk_frame_new (NULL);
	gtk_widget_set_name (frameUserPaths, "frameUserPaths");
	gtk_widget_show (frameUserPaths);
	gtk_box_pack_start (GTK_BOX (hboxGraph), frameUserPaths, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (frameUserPaths), 3);

	vboxUserPaths = gtk_vbox_new (FALSE, 0);
	gtk_widget_set_name (vboxUserPaths, "vboxUserPaths");
	gtk_widget_show (vboxUserPaths);
	gtk_container_add (GTK_CONTAINER (frameUserPaths), vboxUserPaths);
	gtk_container_set_border_width (GTK_CONTAINER (vboxUserPaths), 3);

	hboxGraphDataRefresh = gtk_hbox_new (FALSE, 5);
	gtk_widget_set_name (hboxGraphDataRefresh, "hboxGraphDataRefresh");
	gtk_widget_show (hboxGraphDataRefresh);
	gtk_box_pack_start (GTK_BOX (vboxUserPaths), hboxGraphDataRefresh, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (hboxGraphDataRefresh), 5);

	buttonRefreshGraph = gtk_button_new_from_stock ("gtk-refresh");
	gtk_widget_set_name (buttonRefreshGraph, "buttonRefreshGraph");
	gtk_widget_show (buttonRefreshGraph);
	gtk_box_pack_start (GTK_BOX (hboxGraphDataRefresh), buttonRefreshGraph, FALSE, FALSE, 0);

	optionmenuUsers = gtk_option_menu_new ();
	gtk_widget_set_name (optionmenuUsers, "Active User List");
	gtk_widget_show (optionmenuUsers);
	gtk_box_pack_start (GTK_BOX (hboxGraphDataRefresh), optionmenuUsers, FALSE, FALSE, 0);

	menu1 = gtk_menu_new ();
	gtk_widget_set_name (menu1, "User List");
	gnome_app_fill_menu (GTK_MENU_SHELL (menu1), menu1_uiinfo,
                  	  NULL, FALSE, 0);

	gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenuUsers), menu1);

	scrolledwindowPaths = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_set_name (scrolledwindowPaths, "scrolledwindowPaths");
	gtk_widget_show (scrolledwindowPaths);
	gtk_box_pack_start (GTK_BOX (vboxUserPaths), scrolledwindowPaths, TRUE, TRUE, 0);

	treeviewGraph = create_view_and_model_Graph();
	gtk_widget_set_name (treeviewGraph, "treeviewGraph");
	gtk_widget_show (treeviewGraph);
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeviewGraph), TRUE);
	gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeviewGraph), TRUE);
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(treeviewGraph), TRUE);
	gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW(treeviewGraph), TRUE);
	gtk_tree_view_set_reorderable (GTK_TREE_VIEW(treeviewGraph), TRUE);

	gtk_container_add (GTK_CONTAINER (scrolledwindowPaths), treeviewGraph);
	gtk_container_set_border_width (GTK_CONTAINER (treeviewGraph), 5);
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeviewGraph), TRUE);
	gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeviewGraph), TRUE);
	
	labelUserPaths = gtk_label_new ("User Paths");
	gtk_widget_set_name (labelUserPaths, "labelUserPaths");
	gtk_widget_show (labelUserPaths);
	gtk_frame_set_label_widget (GTK_FRAME (frameUserPaths), labelUserPaths);
	gtk_label_set_justify (GTK_LABEL (labelUserPaths), GTK_JUSTIFY_LEFT);

	labelPageGraph = gtk_label_new ("Graph");
	gtk_widget_set_name (labelPageGraph, "labelPageGraph");
	gtk_widget_show (labelPageGraph);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebookData), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebookData), 1), labelPageGraph);
	gtk_label_set_justify (GTK_LABEL (labelPageGraph), GTK_JUSTIFY_LEFT);
	

	/* Freshly Imported ... */
	vpanedMonitor = gtk_vpaned_new ();
	gtk_widget_show (vpanedMonitor);
	gtk_container_add (GTK_CONTAINER (notebookData), vpanedMonitor);
	gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (notebookData), vpanedMonitor,
                                 	  FALSE, FALSE, GTK_PACK_START);
	gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (notebookData), vpanedMonitor,
                                 	_("Monitor"));
	gtk_container_set_border_width (GTK_CONTAINER (vpanedMonitor), 2);
	GTK_WIDGET_UNSET_FLAGS (vpanedMonitor, GTK_CAN_FOCUS);

	scrolledwindowMonitors = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (scrolledwindowMonitors);
	gtk_paned_pack1 (GTK_PANED (vpanedMonitor), scrolledwindowMonitors, TRUE, TRUE);
	gtk_widget_set_usize (scrolledwindowMonitors, -2, 300);
	gtk_container_set_border_width (GTK_CONTAINER (scrolledwindowMonitors), 10);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindowMonitors), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	treeviewMonitors = create_view_and_model_Monitor(appW3Live);
	gtk_widget_set_name (treeviewMonitors, "treeviewMonitors");
	
	gtk_widget_show (treeviewMonitors);
	gtk_container_add (GTK_CONTAINER (scrolledwindowMonitors), treeviewMonitors);
	gtk_container_set_border_width (GTK_CONTAINER (treeviewMonitors), 10);

	notebookMonitorConfig = gtk_notebook_new ();
	gtk_widget_show (notebookMonitorConfig);
	gtk_paned_pack2 (GTK_PANED (vpanedMonitor), notebookMonitorConfig, TRUE, TRUE);
	gtk_container_set_border_width (GTK_CONTAINER (notebookMonitorConfig), 10);
	gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebookMonitorConfig), GTK_POS_BOTTOM);

	vboxDescription = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vboxDescription);
	gtk_container_add (GTK_CONTAINER (notebookMonitorConfig), vboxDescription);

	labelDescription = gtk_label_new (_("<b>Monitor Description:</b>"));
	gtk_widget_show (labelDescription);
	gtk_box_pack_start (GTK_BOX (vboxDescription), labelDescription, FALSE, FALSE, 0);
	gtk_label_set_use_markup (GTK_LABEL (labelDescription), TRUE);

	scrolledwindowDescription = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (scrolledwindowDescription);
	gtk_box_pack_start (GTK_BOX (vboxDescription), scrolledwindowDescription, TRUE, TRUE, 0);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindowDescription), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	textviewMonitorDescription = gtk_text_view_new ();
	gtk_widget_show (textviewMonitorDescription);
	gtk_container_add (GTK_CONTAINER (scrolledwindowDescription), textviewMonitorDescription);
	gtk_container_set_border_width (GTK_CONTAINER (textviewMonitorDescription), 5);
	gtk_text_view_set_editable (GTK_TEXT_VIEW (textviewMonitorDescription), FALSE);
	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textviewMonitorDescription), GTK_WRAP_WORD);
	gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textviewMonitorDescription), FALSE);
	gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (textviewMonitorDescription), 5);
	gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (textviewMonitorDescription), 5);
	gtk_text_view_set_left_margin (GTK_TEXT_VIEW (textviewMonitorDescription), 5);
	gtk_text_view_set_right_margin (GTK_TEXT_VIEW (textviewMonitorDescription), 5);

	labelTabDescription = gtk_label_new (_("Description"));
	gtk_widget_show (labelTabDescription);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebookMonitorConfig), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebookMonitorConfig), 0), labelTabDescription);
	gtk_label_set_justify (GTK_LABEL (labelTabDescription), GTK_JUSTIFY_LEFT);

	vboxConfigure = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vboxConfigure);
	gtk_container_add (GTK_CONTAINER (notebookMonitorConfig), vboxConfigure);

	labelConfiguration = gtk_label_new (_("<b>Configuration:</b>"));
	gtk_widget_show (labelConfiguration);
	gtk_box_pack_start (GTK_BOX (vboxConfigure), labelConfiguration, FALSE, FALSE, 0);
	gtk_label_set_use_markup (GTK_LABEL (labelConfiguration), TRUE);
	gtk_label_set_justify (GTK_LABEL (labelConfiguration), GTK_JUSTIFY_LEFT);

	labelTabConfigure = gtk_label_new (_("Configure"));
	gtk_widget_show (labelTabConfigure);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebookMonitorConfig), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebookMonitorConfig), 1), labelTabConfigure);
	gtk_label_set_justify (GTK_LABEL (labelTabConfigure), GTK_JUSTIFY_LEFT);

	vboxMActionSup = gtk_vbox_new (FALSE, 5);
	gtk_widget_show (vboxMActionSup);
	gtk_container_add (GTK_CONTAINER (notebookMonitorConfig), vboxMActionSup);
	gtk_container_set_border_width (GTK_CONTAINER (vboxMActionSup), 5);

	labelMAction = gtk_label_new (_("<b>Action to perform:</b>"));
	gtk_widget_show (labelMAction);
	gtk_box_pack_start (GTK_BOX (vboxMActionSup), labelMAction, FALSE, FALSE, 0);
	gtk_widget_set_usize (labelMAction, 53, -2);
	gtk_label_set_use_markup (GTK_LABEL (labelMAction), TRUE);
	gtk_label_set_justify (GTK_LABEL (labelMAction), GTK_JUSTIFY_LEFT);

	vboxMActionSub = gtk_vbox_new (FALSE, 5);
	gtk_widget_show (vboxMActionSub);
	gtk_box_pack_start (GTK_BOX (vboxMActionSup), vboxMActionSub, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (vboxMActionSub), 5);

	hboxMActionPopup = gtk_hbox_new (FALSE, 5);
	gtk_widget_show (hboxMActionPopup);
	gtk_box_pack_start (GTK_BOX (vboxMActionSub), hboxMActionPopup, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (hboxMActionPopup), 5);

	radiobuttonActionPopup = gtk_radio_button_new_with_mnemonic (NULL, _("Popup Message"));
	gtk_widget_show (radiobuttonActionPopup);
	gtk_box_pack_start (GTK_BOX (hboxMActionPopup), radiobuttonActionPopup, FALSE, FALSE, 0);
	gtk_widget_set_usize (radiobuttonActionPopup, 160, -2);
	gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobuttonActionPopup), radiobuttonActionPopup_group);
	radiobuttonActionPopup_group = gtk_radio_button_group (GTK_RADIO_BUTTON (radiobuttonActionPopup));
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobuttonActionPopup), TRUE);

	hseparatorMAction = gtk_hseparator_new ();
	gtk_widget_show (hseparatorMAction);
	gtk_box_pack_start (GTK_BOX (vboxMActionSub), hseparatorMAction, FALSE, TRUE, 0);

	hboxMActionExecute = gtk_hbox_new (FALSE, 5);
	gtk_widget_show (hboxMActionExecute);
	gtk_box_pack_start (GTK_BOX (vboxMActionSub), hboxMActionExecute, FALSE, FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (hboxMActionExecute), 5);

	radiobuttonActionExecute = gtk_radio_button_new_with_mnemonic (NULL, _("Execute script\nor program"));
	gtk_widget_show (radiobuttonActionExecute);
	gtk_box_pack_start (GTK_BOX (hboxMActionExecute), radiobuttonActionExecute, FALSE, FALSE, 0);
	gtk_widget_set_usize (radiobuttonActionExecute, 160, -2);
	gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobuttonActionExecute), radiobuttonActionPopup_group);
	radiobuttonActionPopup_group = gtk_radio_button_group (GTK_RADIO_BUTTON (radiobuttonActionExecute));

	vboxScript = gtk_vbox_new (FALSE, 5);
	gtk_widget_show (vboxScript);
	gtk_box_pack_start (GTK_BOX (hboxMActionExecute), vboxScript, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (vboxScript), 5);

	fileentryMExeFile = gnome_file_entry_new ("MExeFile", _("Program or Script to execute"));
	gtk_widget_show (fileentryMExeFile);
	gtk_box_pack_start (GTK_BOX (vboxScript), fileentryMExeFile, FALSE, FALSE, 0);

	combo_entryMExeFile = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (fileentryMExeFile));
	gtk_widget_show (combo_entryMExeFile);

	hbuttonboxScript = gtk_hbutton_box_new ();
	gtk_widget_show (hbuttonboxScript);
	gtk_box_pack_start (GTK_BOX (vboxScript), hbuttonboxScript, FALSE, FALSE, 0);
	gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonboxScript), GTK_BUTTONBOX_START);
	gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonboxScript), 0);

	buttonMButtonScripts = gtk_button_new ();
	gtk_widget_show (buttonMButtonScripts);
	gtk_container_add (GTK_CONTAINER (hbuttonboxScript), buttonMButtonScripts);
	GTK_WIDGET_SET_FLAGS (buttonMButtonScripts, GTK_CAN_DEFAULT);

	alignmentMButtonScripts = gtk_alignment_new (0.5, 0.5, 0, 0);
	gtk_widget_show (alignmentMButtonScripts);
	gtk_container_add (GTK_CONTAINER (buttonMButtonScripts), alignmentMButtonScripts);

	hboxButtonMButtonScripts = gtk_hbox_new (FALSE, 2);
	gtk_widget_show (hboxButtonMButtonScripts);
	gtk_container_add (GTK_CONTAINER (alignmentMButtonScripts), hboxButtonMButtonScripts);

	imageMButtonScripts = gtk_image_new_from_stock ("gtk-dialog-info", GTK_ICON_SIZE_BUTTON);
	gtk_widget_show (imageMButtonScripts);
	gtk_box_pack_start (GTK_BOX (hboxButtonMButtonScripts), imageMButtonScripts, FALSE, FALSE, 0);

	labelMButtonScripts = gtk_label_new_with_mnemonic (_("Running Scripts"));
	gtk_widget_show (labelMButtonScripts);
	gtk_box_pack_start (GTK_BOX (hboxButtonMButtonScripts), labelMButtonScripts, FALSE, FALSE, 0);
	gtk_label_set_justify (GTK_LABEL (labelMButtonScripts), GTK_JUSTIFY_LEFT);

	labelTabAction = gtk_label_new (_("Action"));
	gtk_widget_show (labelTabAction);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebookMonitorConfig), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebookMonitorConfig), 2), labelTabAction);
	gtk_label_set_justify (GTK_LABEL (labelTabAction), GTK_JUSTIFY_LEFT);

	labelTabMonitor = gtk_label_new (_("Monitor"));
	gtk_widget_show (labelTabMonitor);
	gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebookData), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebookData), 2), labelTabMonitor);
	gtk_label_set_justify (GTK_LABEL (labelTabMonitor), GTK_JUSTIFY_LEFT);

	gtk_signal_connect (GTK_OBJECT (treeviewMonitors), "row_activated",
                  	 GTK_SIGNAL_FUNC (monitorSelectMonitor),
                  	 NULL);
	gtk_signal_connect (GTK_OBJECT (buttonMButtonScripts), "clicked",
                  	 GTK_SIGNAL_FUNC (Popup),
                  	 NULL);

	/* End Freshly Imported */

	appbarMain = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_NEVER);
	gtk_widget_set_name (appbarMain, "appbarMain");
	gtk_widget_show (appbarMain);
	gnome_app_set_statusbar (GNOME_APP (appW3Live), appbarMain);

	gtk_signal_connect (GTK_OBJECT (appW3Live), "destroy",
			GTK_SIGNAL_FUNC (gtk_main_quit),
			NULL);

	gnome_app_install_menu_hints (GNOME_APP (appW3Live), menubarMain_uiinfo);
	gtk_signal_connect (GTK_OBJECT (optionmenuUsers), "changed",
			GTK_SIGNAL_FUNC (displayUserPath),
			(void *)appW3Live);
	
	gtk_signal_connect (GTK_OBJECT(buttonViewWebgraph), "clicked",
			GTK_SIGNAL_FUNC (viewWebGraph),
			(void *)appW3Live);

	/* Store pointers to all widgets, for use by lookup_widget(). */
	GLADE_HOOKUP_OBJECT_NO_REF (appW3Live, appW3Live, "appW3Live");
	GLADE_HOOKUP_OBJECT_NO_REF (appW3Live, w3lc, "w3lc");
	GLADE_HOOKUP_OBJECT (appW3Live, bonobodock1, "bonobodock1");
	GLADE_HOOKUP_OBJECT (appW3Live, menubarMain_uiinfo[0].widget, "menuFile");
	GLADE_HOOKUP_OBJECT (appW3Live, menuFile_menu_uiinfo[0].widget, "menuSave");
	GLADE_HOOKUP_OBJECT (appW3Live, menuFile_menu_uiinfo[1].widget, "menuSaveAs");
	GLADE_HOOKUP_OBJECT (appW3Live, menuFile_menu_uiinfo[2].widget, "separator1");
	GLADE_HOOKUP_OBJECT (appW3Live, menuFile_menu_uiinfo[3].widget, "menuQuit");
	GLADE_HOOKUP_OBJECT (appW3Live, menubarMain_uiinfo[1].widget, "menuHelp");
	GLADE_HOOKUP_OBJECT (appW3Live, menuHelp_menu_uiinfo[0].widget, "menuAbout");
	GLADE_HOOKUP_OBJECT (appW3Live, notebookData, "notebookData");
	GLADE_HOOKUP_OBJECT (appW3Live, frameActiveUsers, "frameActiveUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxActiveUsers, "vboxActiveUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, tableUsersRefresh, "tableUsersRefresh");
	GLADE_HOOKUP_OBJECT (appW3Live, labelRefreshRate, "labelRefreshRate");
	GLADE_HOOKUP_OBJECT (appW3Live, buttonRefreshUsers, "buttonRefreshUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, imageRefresh, "imageRefresh");
	GLADE_HOOKUP_OBJECT (appW3Live, spinbuttonRefreshRate, "spinbuttonRefreshRate");
	GLADE_HOOKUP_OBJECT (appW3Live, scrolledwindowUsers, "scrolledwindowUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, treeviewUsers, "treeviewUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, labelActiveUsers, "labelActiveUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, labelPageUsers, "labelPageUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxGraph, "vboxGraph");
	GLADE_HOOKUP_OBJECT (appW3Live, hboxGraph, "hboxGraph");
	GLADE_HOOKUP_OBJECT (appW3Live, frameGraphButtons, "frameGraphButtons");
	GLADE_HOOKUP_OBJECT (appW3Live, vbuttonboxGraphButtons, "vbuttonboxGraphButtons");
	GLADE_HOOKUP_OBJECT (appW3Live, buttonViewWebgraph, "buttonViewWebgraph");
	GLADE_HOOKUP_OBJECT (appW3Live, alignmentVWG, "alignmentVWG");
	GLADE_HOOKUP_OBJECT (appW3Live, hboxVWG, "hboxVWG");
	GLADE_HOOKUP_OBJECT (appW3Live, imageVWGWarn, "imageVWGWarn");
	GLADE_HOOKUP_OBJECT (appW3Live, labelViewWebGraph, "labelViewWebGraph");
	GLADE_HOOKUP_OBJECT (appW3Live, labelGraphButtons, "labelGraphButtons");
	GLADE_HOOKUP_OBJECT (appW3Live, frameUserPaths, "frameUserPaths");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxUserPaths, "vboxUserPaths");
	GLADE_HOOKUP_OBJECT (appW3Live, hboxGraphDataRefresh, "hboxGraphDataRefresh");
	GLADE_HOOKUP_OBJECT (appW3Live, buttonRefreshGraph, "buttonRefreshGraph");
	GLADE_HOOKUP_OBJECT (appW3Live, optionmenuUsers, "optionmenuUsers");
	GLADE_HOOKUP_OBJECT (appW3Live, menu1, "menu1");
	GLADE_HOOKUP_OBJECT (appW3Live, scrolledwindowPaths, "scrolledwindowPaths");
	GLADE_HOOKUP_OBJECT (appW3Live, treeviewGraph, "treeviewGraph");
	GLADE_HOOKUP_OBJECT (appW3Live, labelUserPaths, "labelUserPaths");
	GLADE_HOOKUP_OBJECT (appW3Live, labelPageGraph, "labelPageGraph");
	GLADE_HOOKUP_OBJECT (appW3Live, appbarMain, "appbarMain");

	GLADE_HOOKUP_OBJECT (appW3Live, vpanedMonitor, "vpanedMonitor");
	GLADE_HOOKUP_OBJECT (appW3Live, scrolledwindowMonitors, "scrolledwindowMonitors");
	GLADE_HOOKUP_OBJECT (appW3Live, treeviewMonitors, "treeviewMonitors");
	GLADE_HOOKUP_OBJECT (appW3Live, notebookMonitorConfig, "notebookMonitorConfig");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxDescription, "vboxDescription");
	GLADE_HOOKUP_OBJECT (appW3Live, labelDescription, "labelDescription");
	GLADE_HOOKUP_OBJECT (appW3Live, scrolledwindowDescription, "scrolledwindowDescription");
	GLADE_HOOKUP_OBJECT (appW3Live, textviewMonitorDescription, "textviewMonitorDescription");
	GLADE_HOOKUP_OBJECT (appW3Live, labelTabDescription, "labelTabDescription");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxConfigure, "vboxConfigure");
	GLADE_HOOKUP_OBJECT (appW3Live, labelConfiguration, "labelConfiguration");

	GLADE_HOOKUP_OBJECT (appW3Live, labelTabConfigure, "labelTabConfigure");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxMActionSup, "vboxMActionSup");
	GLADE_HOOKUP_OBJECT (appW3Live, labelMAction, "labelMAction");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxMActionSub, "vboxMActionSub");
	GLADE_HOOKUP_OBJECT (appW3Live, hboxMActionPopup, "hboxMActionPopup");
	GLADE_HOOKUP_OBJECT (appW3Live, radiobuttonActionPopup, "radiobuttonActionPopup");
	GLADE_HOOKUP_OBJECT (appW3Live, hseparatorMAction, "hseparatorMAction");
	GLADE_HOOKUP_OBJECT (appW3Live, hboxMActionExecute, "hboxMActionExecute");
	GLADE_HOOKUP_OBJECT (appW3Live, radiobuttonActionExecute, "radiobuttonActionExecute");
	GLADE_HOOKUP_OBJECT (appW3Live, vboxScript, "vboxScript");
	GLADE_HOOKUP_OBJECT (appW3Live, fileentryMExeFile, "fileentryMExeFile");
	GLADE_HOOKUP_OBJECT (appW3Live, combo_entryMExeFile, "combo_entryMExeFile");
	GLADE_HOOKUP_OBJECT (appW3Live, hbuttonboxScript, "hbuttonboxScript");
	GLADE_HOOKUP_OBJECT (appW3Live, buttonMButtonScripts, "buttonMButtonScripts");
	GLADE_HOOKUP_OBJECT (appW3Live, alignmentMButtonScripts, "alignmentMButtonScripts");
	GLADE_HOOKUP_OBJECT (appW3Live, hboxButtonMButtonScripts, "hboxButtonMButtonScripts");
	GLADE_HOOKUP_OBJECT (appW3Live, imageMButtonScripts, "imageMButtonScripts");
	GLADE_HOOKUP_OBJECT (appW3Live, labelMButtonScripts, "labelMButtonScripts");
	GLADE_HOOKUP_OBJECT (appW3Live, labelTabAction, "labelTabAction");
	GLADE_HOOKUP_OBJECT (appW3Live, labelTabMonitor, "labelTabMonitor");
	
	
	if(pthread_create(&tid,NULL,(thread_update_stats),(void *)appW3Live))
		perror_exit("%s %d: ",__FILE__,__LINE__);

	return appW3Live;
}

void
saveLOGML                              (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{
	return;
}

void
saveLOGMLAs                            (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{
	return;
}

              
void
displayUserPath                        (GtkOptionMenu   *optionmenu,
                                        gpointer         user_data)
{
	GtkWidget *app = (GtkWidget *)user_data;
	w3lclient *w3lc = (w3lclient *)lookup_widget(app,"w3lc");
	GtkOptionMenu *options = (GtkOptionMenu *)lookup_widget(app,"optionmenuUsers");
	GtkMenu *menu;
	GtkMenuItem *menuitem;

	if(GTK_BIN(options)->child) {
		GtkWidget *child = GTK_BIN (options)->child;
		if (GTK_IS_LABEL (child)) {
			char *text;
			gtk_label_get (GTK_LABEL (child), &text);
			if(text[0] != '\0')
				SetPathInfo(w3lc,app,strdup(text));
      }
	}
	return;
}

void
viewWebGraph                           (GtkButton       *button,
                                        gpointer         user_data)
{
	char *xgmml;
	w3lclient *w3lc;
	GtkWidget *graph = NULL;

	w3lc = (w3lclient *)lookup_widget((GtkWidget *)user_data,"w3lc");

	xgmml = w3lRequest(w3lc,"webgraph()");
	if(!strlen(xgmml)) {
		gtk_widget_show(create_conn_fail("Graph Unavailable"));
		return;
	}
	graph = create_graph(xgmml);
	gtk_widget_show(graph);
}

void
monitorSelectMonitor                   (GtkTreeView     *treeview,
                                        GtkTreePath     *arg1,
                                        GtkTreeViewColumn *arg2,
                                        gpointer         user_data)
{

}


void
Popup                                  (GtkButton       *button,
                                        gpointer         user_data)
{

}

